/*
 * Copyright 2022 MindMotion Microelectronics Co., Ltd.
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef __BOARD_INIT_H__
#define __BOARD_INIT_H__

#include <stdio.h>
#include <stdint.h>

#include "hal_common.h"
#include "hal_slcd.h"

#include "clock_init.h"

/* DEBUG UART. */
#define BOARD_DEBUG_UART_PORT        UART2
#define BOARD_DEBUG_UART_BAUDRATE    9600u
#define BOARD_DEBUG_UART_FREQ        CLOCK_APB1_FREQ

/* SLCD. */
#define BOARD_SLCD_PORT          SLCD
#define BOARD_SLCD_DIV0          1u
#define BOARD_SLCD_DIV1          2u
#define BOARD_SLCD_CHARGEPUMPDIV 1u
#define BOARD_SLCD_BRIGHTNESS    5u
#define BOARD_SLCD_DUTYCYCLE     SLCD_DutyCycle_Div4 /* 1/4 duty cycle. */
#define BOARD_SLCD_BIASMODE      SLCD_BiasMode_Div3  /* 1/3 bias mode. */

#define BOARD_SLCD_COM_NUM    4u  /* Number of common pins. */
#define BOARD_SLCD_SEG_NUM    41u /* Number of segment pins. */

#define BOARD_SLCD_COM0       0u /* Common 0. */
#define BOARD_SLCD_COM1       1u /* Common 1. */
#define BOARD_SLCD_COM2       2u /* Common 2. */
#define BOARD_SLCD_COM3       3u /* Common 3. */

#define BOARD_SLCD_COM0_PIN   35u /* COM0 -> L35. */
#define BOARD_SLCD_COM1_PIN   40u /* COM1 -> L40. */
#define BOARD_SLCD_COM2_PIN   0u  /* COM2 -> L0. */
#define BOARD_SLCD_COM3_PIN   1u  /* COM3 -> L1. */

#define BOARD_SLCD_SEG0_PIN   2u  /* Segment 0 -> L2. */
#define BOARD_SLCD_SEG1_PIN   3u  /* Segment 1 -> L3. */
#define BOARD_SLCD_SEG2_PIN   4u  /* Segment 2 -> L4. */
#define BOARD_SLCD_SEG3_PIN   5u  /* Segment 3 -> L5. */
#define BOARD_SLCD_SEG4_PIN   6u  /* Segment 4 -> L6. */
#define BOARD_SLCD_SEG5_PIN   7u  /* Segment 5 -> L7. */
#define BOARD_SLCD_SEG6_PIN   8u  /* Segment 6 -> L8. */
#define BOARD_SLCD_SEG7_PIN   9u  /* Segment 7 -> L9. */
#define BOARD_SLCD_SEG8_PIN   10u /* Segment 8 -> L10. */
#define BOARD_SLCD_SEG9_PIN   11u /* Segment 9 -> L11. */
#define BOARD_SLCD_SEG10_PIN  12u /* Segment 10 -> L12. */
#define BOARD_SLCD_SEG11_PIN  13u /* Segment 11 -> L13. */
#define BOARD_SLCD_SEG12_PIN  14u /* Segment 12 -> L14. */
#define BOARD_SLCD_SEG13_PIN  15u /* Segment 13 -> L15. */
#define BOARD_SLCD_SEG14_PIN  16u /* Segment 14 -> L16. */
#define BOARD_SLCD_SEG15_PIN  17u /* Segment 15 -> L17. */
#define BOARD_SLCD_SEG16_PIN  18u /* Segment 16 -> L18. */
#define BOARD_SLCD_SEG17_PIN  19u /* Segment 17 -> L19. */
#define BOARD_SLCD_SEG18_PIN  20u /* Segment 18 -> L20. */
#define BOARD_SLCD_SEG19_PIN  21u /* Segment 19 -> L21. */
#define BOARD_SLCD_SEG20_PIN  22u /* Segment 20 -> L22. */
#define BOARD_SLCD_SEG21_PIN  23u /* Segment 21 -> L23. */
#define BOARD_SLCD_SEG22_PIN  24u /* Segment 22 -> L24. */
#define BOARD_SLCD_SEG23_PIN  25u /* Segment 23 -> L25. */
#define BOARD_SLCD_SEG24_PIN  26u /* Segment 24 -> L26. */
#define BOARD_SLCD_SEG25_PIN  27u /* Segment 25 -> L27. */
#define BOARD_SLCD_SEG26_PIN  28u /* Segment 26 -> L28. */
#define BOARD_SLCD_SEG27_PIN  29u /* Segment 27 -> L29. */
#define BOARD_SLCD_SEG28_PIN  30u /* Segment 28 -> L30. */
#define BOARD_SLCD_SEG29_PIN  31u /* Segment 29 -> L31. */
#define BOARD_SLCD_SEG30_PIN  32u /* Segment 30 -> L32. */
#define BOARD_SLCD_SEG31_PIN  33u /* Segment 31 -> L33. */
#define BOARD_SLCD_SEG32_PIN  34u /* Segment 32 -> L34. */
#define BOARD_SLCD_SEG33_PIN  36u /* Segment 33 -> L36. */
#define BOARD_SLCD_SEG34_PIN  37u /* Segment 34 -> L37. */
#define BOARD_SLCD_SEG35_PIN  38u /* Segment 35 -> L38. */
#define BOARD_SLCD_SEG36_PIN  39u /* Segment 36 -> L39. */
#define BOARD_SLCD_SEG37_PIN  41u /* Segment 37 -> L41. */
#define BOARD_SLCD_SEG38_PIN  42u /* Segment 38 -> L42. */
#define BOARD_SLCD_SEG39_PIN  43u /* Segment 39 -> L43. */
#define BOARD_SLCD_SEG40_PIN  58u /* Segment 40 -> L58. */

#define BOARD_SLCD_COM_PIN_BUFF    BOARD_SLCD_COM0_PIN, BOARD_SLCD_COM1_PIN,\
                                   BOARD_SLCD_COM2_PIN, BOARD_SLCD_COM3_PIN

#define BOARD_SLCD_SEG_PIN_BUFF    BOARD_SLCD_SEG0_PIN, BOARD_SLCD_SEG1_PIN, BOARD_SLCD_SEG2_PIN,\
                                   BOARD_SLCD_SEG3_PIN, BOARD_SLCD_SEG4_PIN, BOARD_SLCD_SEG5_PIN,\
                                   BOARD_SLCD_SEG6_PIN, BOARD_SLCD_SEG7_PIN, BOARD_SLCD_SEG8_PIN,\
                                   BOARD_SLCD_SEG9_PIN, BOARD_SLCD_SEG10_PIN, BOARD_SLCD_SEG11_PIN,\
                                   BOARD_SLCD_SEG12_PIN, BOARD_SLCD_SEG13_PIN, BOARD_SLCD_SEG14_PIN,\
                                   BOARD_SLCD_SEG15_PIN, BOARD_SLCD_SEG16_PIN, BOARD_SLCD_SEG17_PIN,\
                                   BOARD_SLCD_SEG18_PIN, BOARD_SLCD_SEG19_PIN, BOARD_SLCD_SEG20_PIN,\
                                   BOARD_SLCD_SEG21_PIN, BOARD_SLCD_SEG22_PIN, BOARD_SLCD_SEG23_PIN,\
                                   BOARD_SLCD_SEG24_PIN, BOARD_SLCD_SEG25_PIN, BOARD_SLCD_SEG26_PIN,\
                                   BOARD_SLCD_SEG27_PIN, BOARD_SLCD_SEG28_PIN, BOARD_SLCD_SEG29_PIN,\
                                   BOARD_SLCD_SEG30_PIN, BOARD_SLCD_SEG31_PIN, BOARD_SLCD_SEG32_PIN,\
                                   BOARD_SLCD_SEG33_PIN, BOARD_SLCD_SEG34_PIN, BOARD_SLCD_SEG35_PIN,\
                                   BOARD_SLCD_SEG36_PIN, BOARD_SLCD_SEG37_PIN, BOARD_SLCD_SEG38_PIN,\
                                   BOARD_SLCD_SEG39_PIN, BOARD_SLCD_SEG40_PIN,

#define BOARD_DELAY_COUNT     10000u

void BOARD_Init(void);

#endif /* __BOARD_INIT_H__ */
